package com.goatstone.client;

import com.goatstone.client.MainWidgetComposite.AlphaCanvasEventHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.event.shared.HandlerRegistration;

public	class AlphabCanvas extends AbsolutePanel implements HasClickHandlers{
	private HandlerRegistration registration;
	protected Long lastElementTimeStamp;
	public AlphaCanvasEventHandler alphaCanvasEventHandler;

	public AlphabCanvas( AlphaCanvasEventHandler alphaCanvasEventHandler){
		super();
		this.alphaCanvasEventHandler = alphaCanvasEventHandler;
		lastElementTimeStamp = new Long(0);
	}	
	public void addDrawElement( DrawElement drawElement ){
		HTML tempDrawElement = new HTML(drawElement.text);
		DOM.setStyleAttribute(tempDrawElement.getElement(), "fontSize", drawElement.fontSize+"px" );		
		DOM.setStyleAttribute(tempDrawElement.getElement(), "color", 
				"rgb("+drawElement.color[0]+","+drawElement.color[1]+","+drawElement.color[2]+")" );		
		add( tempDrawElement , drawElement.x, drawElement.y );
	}
	@Override
	protected void onLoad() {
		super.onLoad();
	}
	@Override
	protected void onUnload() {
		super.onUnload();
		registration.removeHandler();
		registration = null;
	}
	public HandlerRegistration addClickHandler(ClickHandler handler) {
		return addHandler(handler, ClickEvent.getType());
	}
	public void addHandler(){
		registration = addDomHandler( alphaCanvasEventHandler, ClickEvent.getType());
	}	
	public void removeHandler(){
		registration.removeHandler();
		registration = null;
		Window.alert("0 assigned");
	}
}